# Contributor: Noel Kuntze <noel.kuntze@thermi.consulting>
# Maintainer: Noel Kuntze <noel.kuntze@thermi.consulting>
pkgname=e2guardian
pkgver=5.4.5r
pkgrel=1
pkgdesc="fork of dansguardian, an open source web content filter"
url="http://e2guardian.org/"
arch="all"
license="GPL-2.0-only"
depends="logrotate"
makedepends="autoconf automake libtool zlib-dev pcre-dev openssl-dev>3"
install="$pkgname.pre-install"
subpackages="$pkgname-doc $pkgname-openrc"
pkgusers="e2guard"
pkggroups="e2guard"
source="$pkgname-$pkgver.tar.gz::https://github.com/e2guardian/e2guardian/archive/v$pkgver.tar.gz
	e2guardian.initd
	e2guardian.logrotate
	"

# secfixes:
#   5.4.5r-r0:
#     - CVE-2021-44273

prepare() {
	# bind to 127.0.0.1 by default
	sed -i -e 's:^filterip =.*:filterip = 127.0.0.1:' \
			configs/e2guardian.conf.in
	default_prepare
	./autogen.sh
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--sbindir=/usr/bin \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--with-proxyuser=e2guard \
		--with-proxygroup=e2guard \
		--enable-clamd=yes \
		--enable-icap=yes \
		--enable-commandline=yes \
		--enable-email=yes \
		--enable-ntlm=yes \
		--enable-pcre=yes \
		--enable-sslmitm=yes
	make
}

package() {
	make DESTDIR="$pkgdir" install
	install -D -m 755 "$srcdir"/e2guardian.initd \
		"$pkgdir"/etc/init.d/e2guardian
	install -D -m 644 "$srcdir"/e2guardian.logrotate \
		"$pkgdir"/etc/logrotate.d/e2guardian
	install -d -o e2guard -g e2guard "$pkgdir"/var/log/e2guardian
}

sha512sums="
95a35c26335344c5e6a6350a6123a72d5b0221161e238a269a967be08c2bae4191d9ab398660a4760414f433ec3026643248540ff82bc69b8bb551a37bd28e2c  e2guardian-5.4.5r.tar.gz
0be16552e4a4b5541d11de50bef1122462bce71a2ad619d9308a8b92afd6bf350acdf1e3a2ccb40442dd5a70d3ca2c40ba70111798f7d356d5c68a0615aebf1a  e2guardian.initd
480188f7f94e0a08707d4c79ff259f0514b8071499e6112a61df56e7bea6407c0d7f323dcdf998cff17c7187d7eafbf0da5d29ce2ab6f819bf0ba38774f43da5  e2guardian.logrotate
"
